﻿-- Реиндекс всех таблиц
CREATE PROCEDURE [dbo].[USPTOOLS_DBIDX_ReindexAllTables]
WITH EXECUTE AS CALLER
AS
DECLARE reindex_cursor CURSOR 
FOR 
SELECT name FROM sysobjects WHERE type = 'U'
OPEN reindex_cursor
DECLARE @tablename sysname
FETCH NEXT FROM reindex_cursor INTO @tablename 
WHILE (@@FETCH_STATUS <> -1)
	BEGIN
	EXECUTE ('DBCC DBREINDEX (''' + @tablename + ''','''')')
	FETCH NEXT FROM reindex_cursor INTO @tablename
	END 
CLOSE reindex_cursor
DEALLOCATE reindex_cursor


